<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-新建${name_china}</title>
 <%@include file="/common/head.jsp" %>

 <!-- 上传下载插件 -->
 <link href="<%=request.getContextPath()%>/static/plugin/uploadify/style/uploadify.css" rel="stylesheet">
 <script src="<%=request.getContextPath()%>/static/plugin/uploadify/js/jquery.uploadify.js"></script>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

<!-- 下拉树插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/zTree/js/jquery.ztree.all-3.5.min.js"></script>

<!--富文本插件 -->
<script src="<%=request.getContextPath()%>/static/plugin/ckeditor/ckeditor.js"></script>


</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>新建${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="addForm" method="post">
  <div id="left" style="width:80%;float:left">
	 <div class="form-wrapper">
		<div class="h4 distance-double">
	        <span class="h4-title"><i class="icon icon-setting"></i>基本信息</span>
	        <span class="h4-border"></span>
	    </div>
     
        <div class="form-cont">
            <p class="form-cont-title"><span class="field-required">*</span>附件上传</p>
            <!-- 这里写表数据的附件字段  fileId -->
            <input id="fileUpload" name="fileId" type="text" class="summer-input distance-right">
            <label class="label-secondary "></label>
            <!-- 这里一定要写一个id，并且赋值 -->
            <input type="hidden" id="id" name="id" value='${id}'> 
         </div>
     
	    <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>名称</p>
	        <input type="text" id="name" name="name" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[50]']"/> 
	     </div>
	     
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->开始时间</p>
	        <input type="text" id="startTime" name="startTime" class=" summer-input summer-validatebox" onFocus="var afterTime=$dp.$('stopTime');WdatePicker({dateFmt:'yyyy-MM-dd',onpicked:function(){afterTime.focus();},minDate:'#F{(\'%y-%M-%d\')}',maxDate:'#F{$dp.$D(\'stopTime\')}'})" /> 
	     </div>
	     
	    <div class="form-cont">
	        <p class="form-cont-title">结束时间</p>
	        <input type="text" id="stopTime" name="stopTime" class="summer-input" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime\')}'})"/> 
	     </div>
	     
	 
	    <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->简单时间格式</p>
	        <input type="text" id="dateSimple" name="dateSimple" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->详细时间格式</p>
	        <input type="text" id="dateDetail" name="dateDetail" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->下拉选项</p>
	        <input type="text" id="combox" name="combox" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[10]']"/> 
	     </div>
	     
	       <div class="form-cont">0
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->级联下拉选项</p>
	        <input type="text" id="tree" name="tree" class="summer-input" style="width: 220px;" /> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->自定义验证</p>
	        <input type="text" id="verify" name="verify" class="summer-input"/> 
	     </div>
	    
	      <div class="form-cont">
	        <p class="form-cont-title">备注</p>
	        <textarea class="summer-textarea" id="note" name="note"></textarea>
	     </div>
	     
	       <div class="form-cont">
	        <p class="form-cont-title">富文本</p>
	        <textarea class="ckeditor" id="ckeditor" name="ckeditor"></textarea>
	     </div>
	     
	     
	     
	
	 <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
  </div>
	
</form>
<script>
    var  permission = CommonUtil.getPermission('${name_english}');
    $(function () {
    	
    	//初始化下拉选项
    	 $('#combox').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_TEMPLET_COMBOX'
        });
    	
    	//初始化下拉选项
    	$("#tree").comboboxTree({
		    url: COMMON_URL.getCode + '?type=T_DM_TEMPLET_TREE',
		    cIdKey : "id",
		    pIdKey : "pid",
		    setting: {
		        check: {
		            enable: true,
		            chkStyle: "radio",
		            radioType: "all"
		        }
		    },
		    //panelWidth : 220 ,
		    panelHeight: 200
	   });
    	
    	$('#verify').validatebox({
    			      rules:{
    			            regex: {
    			                validator: function (value) {
    			                    var regex = new RegExp("^\\d+\\.\\d{1,"+param[0]+"}$");
    			                    return regex.test(value);
    			                },
    			                message: '自定义验证浮点数'
    			            }
    			        },
    			        tipPosition: 'bottom',
    			        validType: ['regex[3]']
    	});
    	
    	  //初始化附件
	    initUploadConfig();
	   
    	//初始化funcbar
     	$('#funcbar').prepend($.funcbar({
            type: 'button',
            data: permission,
            permit: ['${name_english}:add']
        }));
   	 
    	
    	//保存按钮
    	$('#funcbar').on('click', 'a[data-permit="${name_english}:add"]', {isContinue: false},  submit);
    	
    	//返回按钮
    	$('#backBtn,#goBack').on('click',backMain);
    	
    });
    
    //初始化配置信息
	function initUploadConfig(){
	    var config = {
	            "sessionId" : '${pageContext.session.id}',
	            "formId": "addForm",
	            "items" : [ {
	                'id' : "fileUpload",
	                'fileSizeLimit' : "102400000KB",//大小限制
	                'multi' : true,//是否多文件
	                'required' : false,//是否必填
	                'uploadLimit' : 2,//每次最大上传个数
	                'fileTypeExts' : '*.apk;*.jpg;*.mp4',//限制格式
	                'queueSizeLimit' : 2,//每次队列限制
	                'tableName' : "T_DEMO_TEMPLET",// 表名
	                'field' : 'FILE_ID',// 数据库字段标识
	                'hiddenFileIds' : "fileId"// 存储文件id隐藏框的name，程序自动创建
	            } ]
	        };
	        upLoadUtil.initUplod(config);
	} 
    
    
    
    //表单提交
    function submit(event) {
         $("#addForm").form({
        	 buttons : ['#saveBtn','#saveBtnContinue'],
             ajax: {
                 url: CONST_URL.ADD
             },
             onSubmitSuccess: function (data) {
            	 $.stip({
  	                type:'ok',//显示类型 有info、 ok、 danger
  	                text: '保存成功！',
  	                onBeforeHide: function () {
  	            	  var isContinue = event.data.isContinue;
                   	  if (isContinue) {
                          resetForm();
                   	  } else {
                   		  backMain();
                   	  }
  	               }
              	});
              }
         }).form("submit");
    }
    
    //保存并继续清空form
    function resetForm(){
        //$('#xm,#zw,#cs,#bgdh,#sjhm').val('');
    }
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
   
    //请求url
    var CONST_URL = {
    	INIT_MAIN: basePath + "${common_url}init",
       	ADD: basePath + "${common_url}add"
    };
    
</script>
</body>
</html>